// ... imports
package org.csu.mybigpro.controller;
import org.csu.mybigpro.service.LiveRecordingApiService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

@RestController
@RequestMapping("/api/live/recording")
public class LiveRecordingController {

    private final LiveRecordingApiService liveRecordingApiService;

    public LiveRecordingController(LiveRecordingApiService liveRecordingApiService) {
        this.liveRecordingApiService = liveRecordingApiService;
    }

    @PostMapping("/start")
    public ResponseEntity<?> startRecording(@RequestBody Map<String, String> payload) throws Exception { // 添加 throws Exception
        String roomName = payload.get("roomName");
        String egressId = liveRecordingApiService.startRecording(roomName);
        return ResponseEntity.ok(Map.of("data", Map.of("egressId", egressId)));
    }

    @PostMapping("/stop")
    public ResponseEntity<?> stopRecording(@RequestBody Map<String, String> payload) throws Exception { // 添加 throws Exception
        String egressId = payload.get("egressId");
        liveRecordingApiService.stopRecording(egressId);
        return ResponseEntity.ok(Map.of("message", "Recording stopped successfully."));
    }
}